from utils.sqlutils import SqlUtils
from sqlmap.attendcesqlmap import SqlMap as AttendcesSqlMap


class Attendce:
    def __init__(self):
        self.sqlutils = SqlUtils()

    def attendce_list(self):
        data = self.sqlutils.execute(AttendcesSqlMap.get("list"))
        attendce_list = []
        for row in data.get("content"):
            attendce = {}
            attendce["date"] = row[0]
            attendce["viewname"] = row[1]
            attendce["school_id"] = row[2]
            attendce["department"] = row[3]
            attendce["profession"] = row[4]
            attendce["not_attendce"] = row[5]
            attendce_list.append(attendce)
        return attendce_list

    def attendce_info(self):
        return self.sqlutils.execute(AttendcesSqlMap.get("info"))

    def attendce_create(self, **kwargs):
        return self.sqlutils.execute(AttendcesSqlMap.get("create").format(**kwargs))

    def attendce_delete(self, **kwargs):
        return self.sqlutils.execute(AttendcesSqlMap.get("delete").format(**kwargs))

    def attendce_edit(self, **kwargs):
        return self.sqlutils.execute(AttendcesSqlMap.get("edit").format(**kwargs))
    
    def attendce_later_user(self,**kwargs):
        data = self.sqlutils.execute(AttendcesSqlMap.get("later_user").format(**kwargs))
        user_list = []
        for row in data.get("content"):
            user = {}
            user["id"] = row[0]
            user["username"] = row[1]
            user["image_path"] = row[2]
            user["viewname"] = row[3]
            user_list.append(user)
        return user_list
        

if __name__ == '__main__':
    attendce = Attendce()
    attendce.attendce_create(username="mx",image_path="./storage/mx.jpg",viewname="孟翔")
    # print(user.user_list())
